package com.myjava.managesystem.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.myjava.managesystem.common.BaseContext;
import com.myjava.managesystem.common.R;
import com.myjava.managesystem.entity.Orders;
import com.myjava.managesystem.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrdersController {
    @Autowired
    OrdersService ordersService;


    @GetMapping("/userPage")
    public R<IPage<Orders>> getOrdersPage(@RequestParam int page,@RequestParam int pageSize){
        IPage iPage = new Page(page,pageSize);
        LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Orders::getUserId, BaseContext.getCurrentId());
        iPage = ordersService.page(iPage, wrapper);
        return R.success(iPage);
    }

    @PostMapping("/submit")
    public R<String> submitOrder(@RequestBody Orders order){
        ordersService.submitOrder(order);
        return R.success("提交成功");
    }
}
